<?php
namespace oauth2server\controllers;

use Yii;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use oauth2server\models\PasswordResetRequestForm;
use oauth2server\models\ResetPasswordForm;
use oauth2server\models\SignupForm;
use oauth2server\models\ContactForm;

/**
 * Site controller
 */
class ApiController extends Controller{


    /**
     * {@inheritdoc}
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionIndex(){

        $cates = Yii::$app->params["apiCategories"];

       // $host = Yii::$app->params["oauth2_server_host"];

        $data = [
           // 'host' => $host,
            'cates' => $cates,
        ];

        return $this->renderPartial('index', $data);
    }

    public function actionDetail(){

        $uri = isset($_GET["uri"]) ? $_GET["uri"] : "";

        $apis = Yii::$app->params["apis"];
        $api = [];
        for($i=0; $i<count($apis); $i++){
            if($apis[$i]["uri"] == $uri){
                $api = $apis[$i];
            }
        }

        if(empty($api)){
            exit("找不到API");
        }

        $data = [
            'api' => $api,
        ];

        return $this->renderPartial('detail', $data);
    }

}
